package com.JFapp.controller;


import com.JFapp.domain.dto.LinkDto;
import com.JFapp.domain.entity.Link;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.domain.vo.LinkVo;
import com.JFapp.service.LinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/link")
@Api("友链管理")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @ApiOperation("添加友链")
    @PostMapping()
    public ResponseResult addLink(@RequestBody LinkDto linkDto){
        return linkService.addLink(linkDto);
    }


    @ApiOperation("查询友链")
    @GetMapping("/list")
    public ResponseResult getAllLink(Integer pageNum,Integer pageSize){
        return linkService.getAllLinkInAdmin(pageNum,pageSize);
    }

    @ApiOperation("查询指定友链")
    @GetMapping("/{id}")
    public ResponseResult getOneLinkById(@PathVariable Long id){
        return linkService.getOneLinkById(id);
    }


    @ApiOperation("更新友链")
    @PutMapping
    public ResponseResult updateLink(@RequestBody LinkVo linkVo){
        return linkService.updateLink(linkVo);
    }

    @ApiOperation("删除友链")
    @DeleteMapping("/{id}")
    public ResponseResult deleteLinkById(@PathVariable Long id){
        return linkService.deleteLinkById(id);
    }
}
